package com.atguigu.chapter05.source;

import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer;
import org.apache.flink.streaming.util.serialization.JSONKeyValueDeserializationSchema;

import java.util.Properties;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/7/16 11:28
 */
public class Flink03_Source_Kafka {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
    
        Properties props = new Properties();
        props.setProperty("bootstrap.servers", "hadoop162:9092,hadoop163:9092,hadoop164:9092");
        props.setProperty("group.id", "Flink03_Source_Kafka");
        props.setProperty("auto.reset.offset", "latest");
    
       /* DataStreamSource<String> source = env.addSource(
            new FlinkKafkaConsumer<String>(
                "s1",
                new SimpleStringSchema(),
                props
            )
        );*/
    
        DataStreamSource<ObjectNode> source = env.addSource(
            new FlinkKafkaConsumer<ObjectNode>(
                "s1",
                new JSONKeyValueDeserializationSchema(true),
                props
            )
        );
    
        source
            //.map(node -> node.get("value"))
            .print();
    
        env.execute();
        
    }
    
}
